﻿using System;
using Loki.Model;
using Luna.Data;
using Luna.Data.Configuration;
using Luna.Model;

namespace Luna.Services.Test
{
    public abstract class ReferenceEntityTest<TDataProvider, TEntity, TEntityData> : EntityTest<TDataProvider, TEntity, IReferenceData, TEntityData>
        where TEntityData : ILunaData, IReferenceData
        where TDataProvider : class
        where TEntity : class, ILunaReferenceEntity, IEditable<TEntity>
    {
        public override void SetUp()
        {
            base.SetUp();

            PropertyShifters.Add(new PropertyShifter<TEntity, string>(x => x.Google, DataManager.GetString));
            PropertyShifters.Add(new PropertyShifter<TEntity, DateTime?>(x => x.GoogleLastUpdate, DataManager.GetNullableDate));
            PropertyShifters.Add(new PropertyShifter<TEntity, DateTime?>(x => x.LastUpdate, DataManager.GetNullableDate));
            PropertyShifters.Add(new PropertyShifter<TEntity, int?>(x => x.ZohoCRM, DataManager.GetNullableInt));
            PropertyShifters.Add(new PropertyShifter<TEntity, DateTime?>(x => x.ZohoCRMLastUpdate, DataManager.GetNullableDate));
        }

        protected override bool BuildMatch(TEntity P_Entity, TEntityData P_Data)
        {
            return DataKeyMatch(P_Data, P_Entity);
        }

        protected override IReferenceData DataKey(TEntityData P_Data)
        {
            return P_Data;
        }

        protected override bool DataKeyMatch(IReferenceData P_Parameter, TEntity P_Match)
        {
            bool L_Return = true;

            L_Return &= P_Match.ZohoCRMLastUpdate == P_Parameter.ZohoCRMLastUpdate;
            L_Return &= P_Match.ZohoCRM == P_Parameter.ZohoCRM;
            L_Return &= P_Match.LastUpdate == P_Parameter.LastUpdate;
            L_Return &= P_Match.ID == P_Parameter.PK;
            L_Return &= P_Match.GoogleLastUpdate == P_Parameter.GoogleLastUpdate;
            L_Return &= P_Match.Google == P_Match.Google;

            return L_Return;
        }
    }
}